{% extends "xadmin/base_site.html" %}
{% load i18n %}
{% load url from future %}
{% load xadmin_tags %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
{% if account_view %}
<ul class="breadcrumb">
  <link href="/websys/static/xadmin/vendor/bootstrap-table/css/bootstrap-table.min.css" type="text/css" media="screen" rel="stylesheet" />
<li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li class="active"> {{ title }} </li>
</ul>
{% else %}
<ul class="breadcrumb">
  <li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li>
    {% if has_view_permission %}
    <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
    {% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
  </li>
  <li><a href="{% url opts|admin_urlname:'change' original.pk %}">{{ original|truncatewords:"18" }}</a></li>
  <li class="active">{% trans 'Change password' %}</li>
</ul>
{% endif %}
{% endblock %}

{% block content-nav %}
{% endblock %}
{% block content %}
<!--页面设计在这儿....{{ serverval }}-->
    <style>
    .tb_tr{height: 50px; border:gainsboro 1px  double;}
    .tb_td{height: 50px; border: gainsboro 1px double; width:80px;}
    .td_info_1{background-color: #1da7ee;color: #0C0C0C;width: 100px; border:gainsboro 1px  double;}
    .td_info_2{width: 150px; border:gainsboro 1px  double;}
    .td_info_3{width: 300px; border:gainsboro 1px  double;}
    .txt_10{width: 200px;}
    .txt_30{width: 300px;}
    .td_title_1{font-weight: bold; font-size: 15px;}
    .tr_card_0{background-color: #1da7ee;}
    .tr_card_0 td{width: 80px;}
    .tb_normal{}
    .tb_normal td{border:gainsboro 1px  double;}
    </style>
    <table id="tb_main" style="width: 100%">
        <tr class="tb_tr">
            <td class="tb_td">服务器：</td>
            <td>
                <select id="sel_pf">
                    <option value="" selected="selected">请选择</option>
                    {% for item in htmldata.apps %}
                            <option value="{{ item.pf }}">{{ item.name }}</option>
                    {% endfor %}
                </select>
            </td>
        </tr>
        <tr class="tb_tr" id="tr_day" >
            <td class="tb_td">Uid：</td>
            <td><input type="text" maxlength="40" id="txt_uid" class="txt_30">
                <input type="hidden" id="hid_uid" value="">
                <input type="button" id="bt_copy" value="查询" onclick="toSearch()">
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td td_title_1">状态信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_info">
                    <tr>
                        <td class="td_info_1">用户呢称</td>
                        <td class="td_info_2"><label id="la_nick"></label> </td>
                        <!-- <td class="td_info_1">军衔</td>
                        <td class="td_info_3"><label id="la_military"></label> </td> -->
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">创建时间</td>
                        <td ><label id="la_makeupTime"></label> </td>
                        <td class="td_info_1">创建角色ip</td>
                        <td ><label id="la_role_ip"></label> </td>
                    </tr> -->
                    <tr>
                        <td class="td_info_1">创建时间</td>
                        <td ><label id="la_makeupTime"></label> </td>
                        <td class="td_info_1">最后登陆时间</td>
                        <td ><label id="la_lastlogin"></label> </td>
<!--                         <td class="td_info_1">最后登陆ip</td>
                        <td ><label id="la_role_ip"></label> </td> -->
                    </tr>
                    <tr>
                        <td class="td_info_1">角色经验</td>
                        <td ><label id="la_exp"></label> </td>
                        <td class="td_info_1">vip等级</td>
                        <td ><label id="la_vipLv"></label> </td>
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">职业</td>
                        <td><label id="la_labar"></label> </td>
                        <td class="td_info_1">好友数量</td>
                        <td><label id="la_friend_num"></label> </td>
                    </tr> -->
                    <tr>
                        <td class="td_info_1">战斗力</td>
                        <td ><label id="la_power"></label> </td>
                        <td class="td_info_1">竞技场排行</td>
                        <td ><label id="la_pvp_rank"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">充值金额</td>
                        <td ><label id="la_totalRecharge"></label> </td>
                        <td class="td_info_1">充值次数</td>
                        <td ><label id="la_recharge_num"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">金魂</td>
                        <td ><label id="la_gold"></label> </td>
                        <td class="td_info_1">军团贡献</td>
                        <td ><label id="la_contribution"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">是否购买成长基金</td>
                        <td ><label id="la_is_buy_CZJJ"></label> </td>
                        <td class="td_info_1">是否周卡用户</td>
                        <td ><label id="la_is_week_card"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">是否月卡用户</td>
                        <td ><label id="la_is_month_card"></label> </td>
                        <td class="td_info_1">是否年卡用户</td>
                        <td ><label id="la_is_year_card"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">秘境探宝层数</td>
                        <td ><label id="la_MJTB_level"></label> </td>
                        <td class="td_info_1">好友数量</td>
                        <td ><label id="la_friends_num"></label> </td>
                    </tr>
                    <tr>
                        <td class="td_info_1">过关斩将章节</td>
                        <td ><label id="la_GGZJ_chapter"></label> </td>
                        <td class="td_info_1">当前挂机</td>
                        <td ><label id="la_battle_name"></label> </td>
                    </tr>
   <!--                  <tr>
                        <td class="td_info_1">推图波次</td>
                        <td ><label id="la_tuitu"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td ><input type="text" maxlength="10" id="txt_tuitu"> <input type="button" id="btn_tuitu" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
<!--                     <tr>
                        <td class="td_info_1">爬塔层数</td>
                        <td><label id="la_create_time"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_pata"> <input type="button" id="btn_pata" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
<!--                     <tr>
                        <td class="td_info_1">精英挑战波次</td>
                        <td><label id="la_create_time"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_jiying"> <input type="button" id="btn_jiying" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
<!--                     <tr>
                        <td class="td_info_1">任务波次</td>
                        <td><label id="la_create_time"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_task"> <input type="button" id="btn_task" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
<!--                     <tr>
                        <td class="td_info_1">新手引导波次</td>
                        <td><label id="la_new_lead"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_new_lead"> <input type="button" id="btn_new_lead" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
                     <tr>
                        <td class="td_info_1">Vip经验</td>
                        <td><label id="la_vipexp"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_vipexp"> <input type="button" id="btn_vipexp" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
                     <tr>
                        <td class="td_info_1">元宝</td>
                        <td><label id="la_goldpoint"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_goldpoint"> <input type="button" id="btn_goldpoint" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
<!--                     <tr>
                        <td class="td_info_1">礼券</td>
                        <td><label id="la_coupon"></label> </td>
                        <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_coupon"> <input type="button" id="btn_coupon" onclick="save_data(this)" value="确定"></td>
                    </tr> -->
                    <tr>
                        <td class="td_info_1">铜钱</td>
                        <td><label id="la_gamepoint"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_gamepoint"> <input type="button" id="btn_gamepoint" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
                     <tr>
                        <td class="td_info_1">武魂值</td>
                        <td><label id="la_wuhun"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_wuhun"> <input type="button" id="btn_wuhun" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
                    <tr>
                        <td class="td_info_1">精力值</td>
                        <td><label id="la_GGZJenergy"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_GGZJenergy"> <input type="button" id="btn_GGZJenergy" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
                    <tr>
                        <td class="td_info_1">是否领取一元礼包</td>
                        <td><label id="la_is_get_paygift1"></label> </td>
                        <!-- <td class="td_info_1">修改为</td>
                        <td><input type="text" maxlength="10" id="txt_GGZJenergy"> <input type="button" id="btn_GGZJenergy" onclick="save_data(this)" value="确定"></td> -->
                    </tr>
                </table>
            </td>
        </tr>

        <tr class="tb_tr">
            <td class="tb_td td_title_1">卡牌信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_cards" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>卡牌名称</td>
                        <td>卡牌id</td>
                        <td>卡牌等级</td>
                        <td>卡牌星数</td>
                        <td>培养属性(攻击力|血量)</td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr class="tb_tr">
            <td class="tb_td td_title_1">背包：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_props" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>道具名称</td>
                        <td>道具ID</td>
                        <td>道具数量</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td td_title_1">军团技能：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_skills" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>内容</td>
                        <td>等级</td>
                        <!-- <td>道具数量</td> -->
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td td_title_1">神器信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_goldequ" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>神器名称</td>
                        <td>神器品质</td>
                        <td>神器阶次</td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr class="tb_tr">
            <td class="tb_td td_title_1">装备信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_equipments" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>装备名称</td>
                        <td>装备id</td>
                        <td>装备战力</td>
                        <td>强化等级</td>
                        <td>装备品质</td>
                        <td>精炼等级</td>
                        <td>所属武将位置</td>
                        <!-- <td>洗炼值id</td> -->
                    </tr>
                </table>
            </td>
        </tr>

<!--         <tr class="tb_tr">
            <td class="tb_td td_title_1">任务信息：</td>
            <td></td>
         </tr>
        <tr>
        <td class="tb_td"></td>
            <td>
                <table id="tb_tasks" class="tb_normal">
                    <tr class="tr_card_0">
                        <td>任务名称</td>
                        <td>任务id</td>
                    </tr>
                </table>
            </td>
        </tr> -->

    </table>
    <script>
    //重置数据，查询前清了旧数据
    function resetData()
    {
        if( $('#hid_uid').val()!='')
        {
            //清除labal
            $("#tb_main label").each(function(i){
                if(this.id.indexOf('la_')==0) {
                    //alert(this.id);
                    this.innerHTML = "";
                }
             });
            //清除txt
            $("#tb_main input[type='text']").each(function(i){
                if(this.id.indexOf('_uid')<1) {
                    //alert(this.id);
                    this.value = "";
                }
             });
            //删除表格
            delTable('tb_props');
            delTable('tb_tasks');
            delTable('tb_equipments');
            delTable('tb_cards');
            delTable('tb_skills');
            delTable('tb_goldequ');
            
            
        }
    }
    //查询
    function toSearch()
    {
        var t_uid=$('#txt_uid').val();
        var t_sid=$('#sel_pf').val();
        if(t_uid=='' || t_sid=='')
        {
            alert('请输入uid或服务器');
            return;
        }
        resetData();

        getData(t_uid,t_sid);

    }
    //显示 某个玩家的数据
    function getData(_uid,_sid)
    {
        $.post('/xadmin/ajax_userdata/getuser', {"uid":_uid, "sid":_sid}, function(result){
            //alert(result.code);return;
			if(result.code == 0)
			{
				showData(result.res);
                //有数据就设置，以备修改时用
                $('#hid_uid').val(_uid+','+_sid);
			}else
			{
				alert('查询失败:'+result.code);
			}
		 }, "json");


    }
    function showData(jsonObj)
    {
        //用户属性
        for (var prop in jsonObj.userInfo)
        {
          //alert("jsonObj.userInfo[" + prop + "]=" + jsonObj.userInfo[prop]);
            if ($("#la_"+prop).length > 0) {
                $("#la_"+prop).html(jsonObj.userInfo[prop]);
            }
        }
        //用户属性
        for (var props in jsonObj.otherInfo)
        {
          //alert("jsonObj.userInfo[" + prop + "]=" + jsonObj.userInfo[prop]);
            if ($("#la_"+props).length > 0) {
                $("#la_"+props).html(jsonObj.otherInfo[props]);
            }
        }
        //卡牌
        addTR_Cards(jsonObj.cards);
        //背包
        addTR_Props(jsonObj.bag);
        //技能
        addTR_Skills(jsonObj.union.skills);
        //神器
        addTR_goldequ(jsonObj.ZBInfo.sq_info);
        //装备
        addTR_equipments(jsonObj.ZBInfo.zb_info);

    }
    //保存某个属性
    function save_data(obj)
    {
        //alert(obj.id);

        var tmp_arr=obj.id.split('_');
        var t_key=tmp_arr[1];
        var t_val=$('#txt_'+t_key).val();

        if(t_val=='')
        {
            alert('请输入数值');
            return;
        }

        var tmp_val=$('#hid_uid').val();
        if(tmp_val=='')
        {
            alert('请先查询正确的玩家');
            return;
        }
        tmp_arr=tmp_val.split(',');
        var _uid=tmp_arr[0];
        var _sid=tmp_arr[1];
        $.post('/xadmin/ajax_userdata/saveuser', {"uid":_uid, "sid":_sid,"key":t_key, "value":t_val}, function(result){
            //alert(result.code);return;
			if(result.code == 0)
			{
				$('#la_'+t_key).innerHTML(t_val);
			}else
			{
				alert('修改失败:'+result.code);
			}
		 }, "json");
    }
    //是否有地址栏参数?uid=xxx&sid=xxx
    function getQueryString(){
         result = {}
         r = new RegExp("[\?\&]([^\?\&]+)=([^\?\&]+)","g")
         a = r.exec(location.href)
         while(a)
        {    console.log(a)
             result[a[1]]=a[2]
              a = r.exec(location.href)
        }
         return result;

    }
    function initData()
    {
        var t_uid='',t_sid='';
        var t_obj=getQueryString();
        for(var ii_key in t_obj) {
            if (ii_key=='uid')
            {
                t_uid=t_obj[ii_key];
            }
            else if (ii_key=='sid')
            {
                t_sid=t_obj[ii_key];
            }
        }
        if(t_uid!='' && t_sid!='')
        {
            $('#txt_uid').val(t_uid);
            $('#sel_pf').val(t_sid);
            getData(t_uid,t_sid);
        }

    }
    $(function() {
        initData();
        //addTR_Props();
    });
    //动态表格处理
    function delTable(tid)
    {
        //清空主题Table的数据
        var t=document.getElementById(tid);  //获取Table
        var length= t.rows.length;          //获得Table下的行数
        if(length!=0){              //如果有行，则清空
            for(var i=length-1;i>0;i--)
            {
             t.deleteRow(i);
            }
        }
    }
    function addTR_Props(provinces)
    {
        //var objmoList1=new Array();//数组
        // var objmo=new Object();
        // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
        //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
        //var provinces=new Array();
        //var objmo={'id':0,'name':'qq','num':1};
        //var objmo=new Object();
        //objmo.id=0;objmo.name='qq';objmo.num=12;
        //provinces.push(objmo);

        var t=document.getElementById('tb_props');
        for (var i = 0; i < provinces.length; i++) {
            //tr
           var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.id;
            c = r.insertCell();
            c.innerHTML= tr_data.num;
            }
    }
    //[u'lv', u'star', u'id', u'name']
    function addTR_Cards(provinces)
    {
        //var objmoList1=new Array();//数组
        // var objmo=new Object();
        // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
        //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
        //var provinces=new Array();
        //var objmo={'id':0,'name':'qq','num':1};
        //var objmo=new Object();
        //objmo.id=0;objmo.name='qq';objmo.num=12;
        //provinces.push(objmo);

        var t=document.getElementById('tb_cards');
        for (var i = 0; i < provinces.length; i++) {
            //tr
            var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.id;
            c = r.insertCell();
            c.innerHTML= tr_data.lv;
            c = r.insertCell();
            c.innerHTML= tr_data.star;
            c = r.insertCell();
            if (tr_data.train!=''){
                c.innerHTML= tr_data.train.split('|')[0]+'|'+tr_data.train.split('|')[2];
            }
            else{
                c.innerHTML='0|0';
            }
                 
            }
    }
function addTR_Skills(provinces)
    {
        //var objmoList1=new Array();//数组
        // var objmo=new Object();
        // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
        //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
        //var provinces=new Array();
        //var objmo={'id':0,'name':'qq','num':1};
        //var objmo=new Object();
        //objmo.id=0;objmo.name='qq';objmo.num=12;
        //provinces.push(objmo);

        var t=document.getElementById('tb_skills');
        for (keys in provinces) {
            //tr
           var r = t.insertRow(t.rows.length);//创建新的行
            //var tr_data=provinces[i];
            //td
            var c = r.insertCell();                //创建新的列
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= keys;
            c = r.insertCell();
            c.innerHTML= provinces[keys];
            // c = r.insertCell();
            // c.innerHTML= tr_data.lv;
            // c = r.insertCell();
            // c.innerHTML= tr_data.star;
            // c = r.insertCell();
            // c.innerHTML= tr_data.train.split('|')[0]+'|'+tr_data.train.split('|')[1];
            }
    }

   function addTR_goldequ(provinces)
    {
        //var objmoList1=new Array();//数组
        // var objmo=new Object();
        // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
        //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
        //var provinces=new Array();
        //var objmo={'id':0,'name':'qq','num':1};
        //var objmo=new Object();
        //objmo.id=0;objmo.name='qq';objmo.num=12;
        //provinces.push(objmo);
        var t=document.getElementById('tb_goldequ');
        for (var i = 0; i < provinces.length; i++) {

            //tr
            var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];
            //td
               //创建新的列
            if(tr_data.lv>=1){
                var c = r.insertCell();
                //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
                c.innerHTML= tr_data.name;
                c = r.insertCell();
                c.innerHTML= tr_data.color;
                c = r.insertCell();
                c.innerHTML= tr_data.lv;
        }
            // c = r.insertCell();
            // c.innerHTML= tr_data.lv;
            // c = r.insertCell();
            // c.innerHTML= tr_data.star;
            // c = r.insertCell();
            // c.innerHTML= tr_data.train.split('|')[0]+'|'+tr_data.train.split('|')[1];
            }
    } 
    function addTR_equipments(provinces)
    {
        //var objmoList1=new Array();//数组
        // var objmo=new Object();
        // 对象objmo.s="11";//对象里面的属性objmo.t="22";objmoList1.push(objmo);alert(objmoList1[0].s);
        //var provinces=new Array({'id':0,'name':'qq','num':1},{'id':2,'name':'mm','num':33});
        //var provinces=new Array();
        //var objmo={'id':0,'name':'qq','num':1};
        //var objmo=new Object();
        //objmo.id=0;objmo.name='qq';objmo.num=12;
        //provinces.push(objmo);
        var t=document.getElementById('tb_equipments');
        for (var i = 0; i < provinces.length; i++) {

            //tr
            var r = t.insertRow(t.rows.length);//创建新的行
            var tr_data=provinces[i];//td//创建新的列
            var c = r.insertCell();
            //c.innerHTML = "<input type='checkbox' name='zhutiIds' value="+provinces[i][0]+">"+provinces[i][1];
            c.innerHTML= tr_data.name;
            c = r.insertCell();
            c.innerHTML= tr_data.sid;
             c = r.insertCell();
            c.innerHTML= tr_data.power;
            c = r.insertCell();
            c.innerHTML= tr_data.strengthenLv;
            c = r.insertCell();
            c.innerHTML= tr_data.color;
            c = r.insertCell();
            c.innerHTML= tr_data.refineLv;
            c = r.insertCell();
            c.innerHTML= tr_data.pos;
            }
    } 
    </script>
{% endblock %}